<?php 
global $_W,$_GPC;
$id = intval($_GPC['reciveid']);

$sql = "SELECT * FROM ".tablename('imeepos_runner3_recive')." WHERE id = :id";
$params = array(':id'=>$id);
$recive = pdo_fetch($sql,$params);

$sql = "SELECT * FROM ".tablename('imeepos_runner3_tasks')." WHERE id = :id";
$params = array(':id'=>$recive['taskid']);
$task = pdo_fetch($sql,$params);

if(!empty($task)){
	if($task['status'] == 2){
		$sql = "SELECT * FROM ".tablename('imeepos_runner3_member')." WHERE openid = :openid AND uniacid = :uniacid ";
		$params = array(':openid'=>$recive['openid'],':uniacid'=>$_W['uniacid']);
		$runner = pdo_fetch($sql,$params);
		
		$xinyu = intval($runner['xinyu']);
		
		//获取后台设置
		$table = "imeepos_runner3_setting";
		$code = 'v_set';
		
		//pdo_delete($table);
		
		$sql = "SELECT * FROM ".tablename($table)." WHERE uniacid = :uniacid AND code = :code";
		$params = array(':uniacid'=>$_W['uniacid'],':code'=>$code);
		$setting = pdo_fetch($sql,$params);
		
		$item = iunserializer($setting['value']);
		$kouchu = intval($item['giveup_num']);
		$shengyu = $xinyu - $kouchu;
		if($shengyu > 0 ){
			pdo_update('imeepos_runner3_member',array('xinyu'=>$xinyu-$kouchu),array('id'=>$runner['id']));
			pdo_delete('imeepos_runner3_recive',array('id'=>$id));
			pdo_update('imeepos_runner3_tasks',array('status'=>1),array('id'=>$task['id']));
			
			//可以放弃 扣除相应信誉
			$return = array();
			$return['result'] = 0;
			$return['message'] = '放弃订单成功，您的信誉度-'.$kouchu.'，剩余'.$shengyu.'，点击确定，前往充值';
			die(json_encode($return));
		}else{
			$return = array();
			$return['result'] = -1;
			$return['message'] = '放弃订单失败，信誉度不足，请充值！';
			die(json_encode($return));
		}
	}else if($task['status'] == 4){
		$sql = "SELECT * FROM ".tablename('imeepos_runner3_moneylog')." WHERE reciveid = :reciveid";
		$params = array(':reciveid'=>$reciveid);
		$money = pdo_fetch($sql,$params);
		$return = array();
		$return['result'] =1;
		$return['tid'] = $money['id'];
		$return['message'] = "此订单已完结，不可放弃！";
		die(json_encode($return));
	}else if($task['status'] == 3){
		$return = array();
		$return['result'] = 0;
		$return = array();
		$return['result'] =1;
		$return['tid'] = $money['id'];
		$return['message'] = "等待任务主结款中，不可放弃！";
		die(json_encode($return));
	}
}else{
	$return = array();
	$return['result'] =3;
	$return['message'] = "订单不存在或已删除！请核实！";
	die(json_encode($return));
}

$return = array();
$return['result'] =3;
$return['message'] = "系统错误，请联系站点管理员！";
die(json_encode($return));